import { observable, action, computed } from 'mobx'
import { post } from 'lib/net'
import CommonVM from 'cvm/common'
import * as api from 'lib/constants/api'
import Toast from 'components/toast'

export default class FeedBackVM extends CommonVM {
  constructor (props) {
    super()
    this.props = props
  }

  // 反馈内容
  @observable contentValue = ''

  // 提交按钮样式
  @computed get submitStyle () {
    return this.contentValue.length >= 5
    ? {background: '#15ae67'}
    : []
  }

  // 修改内容
  @action handleChangeContent = e => {
    this.contentValue = e.target.value
  }

  // 意见反馈
  @action handleSubmit = async () => {
    if (this.contentValue.length < 5) return
    let params = {
      UserInfoID: this.userId,
      FeedDackContent: this.contentValue
    }
    Toast.loading(1, '正在反馈')
    let res = await post(api.FEED_BACK, params)
    if (res.state === 1) {
      Toast.loading(2)
      this.props.history.go(-1)
    } else {
      Toast.fail('反馈失败')
    }
  }
}
